#ifndef RENDERER_H
#define RENDERER_H

#include <QWindow>

#include <QVector2D>
#include <QVector3D>
#include <QMatrix4x4>

class QOpenGLContext;
class QOpenGLVertexArrayObject;
class QOpenGLShaderProgram;

class Renderer: public QObject
{
    Q_OBJECT
public:
    Renderer(QString modelDiskPath, QWindow* window);

    void ensureInitialized();

    void setScale(float scale);
    float scale();

    void setOffset(QVector3D offset);
    QVector3D offset();

    void setXyTranslation(QVector2D translation);
    QVector2D xyTranslation();

    void setRotation(QMatrix4x4 rotation);
    QMatrix4x4 rotation();

    void setProjection(QMatrix4x4 projection);
    QMatrix4x4 projection();

    void render();

private slots:
    void onResize();

protected:
    virtual void initialize() =0;
    virtual void doRender() =0;

    void resizeIfNecessary();

    QString m_modelDiskPath;
    QWindow* m_window;

    bool m_initialized;
    bool m_viewportResizeNecessary;

    QOpenGLContext* m_context;

    float m_scale;
    QVector2D m_xyTranslation;
    QMatrix4x4 m_rotation;
    QVector3D m_offset;
    QMatrix4x4 m_projection;
};

#endif // RENDERER_H
